package wangxiaotao.common;

import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Accessors//链式
public class CommonResult implements Serializable,Cloneable,Comparable {

    private Integer code;
    private String message;
    private Object data;
    public CommonResult(Integer code, String message) {
        this(code,message,null);
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    /**
     * 成功
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static CommonResult success(Integer code,String message,Object data){
        return new CommonResult(code,message,data);
    }

    /**
     * 成功 默认code 200 有数据
     * @param message
     * @param data
     * @return
     */
    public static CommonResult success(String message,Object data){
        return new CommonResult(200,message,data);
    }

    /**
     * 成功 返回 200 success 无数据
     * @param data
     * @return
     */
    public static CommonResult success(Object data){
        return success("success",data);
    }

    /**
     * 成功 默认返回200 success null
     * @return
     */
    public static CommonResult success(){
        return success(null);
    }

    /**
     * 失败
     * @param code
     * @param message
     * @param data
     * @return
     */
    public static CommonResult fail(Integer code,String message,Object data){
        return new CommonResult(code,message,data);
    }

    /**
     * 失败 默认400
     * @param message
     * @param data
     * @return
     */
    public static CommonResult fail(String message,Object data){
        return fail(400,message,data);
    }

    /**
     * 失败 默认400 error
     * @param data
     * @return
     */
    public static CommonResult fail(Object data){
        return fail("error",data);
    }

    /**
     * 失败 默认400 error null
     * @return
     */
    public static CommonResult fail(){
        return fail(null);
    }

}
